/*
 *  Locust.c
 *  pr1
 *
 *  Created by Javier Quevedo on 25/01/09.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */
#import "Locust.h"
#import "Node.h"

Locust* initLocust(){
	Locust *newLocust = malloc(sizeof(Locust));
	
	newLocust->files = malloc(sizeof(char)*13*40);
	newLocust->files[0] = "models/locust/antennae.sgf";
	newLocust->files[1] = "models/locust/body.sgf";
	newLocust->files[2] = "models/locust/eyes.sgf";
	newLocust->files[3] = "models/locust/head.sgf";
	newLocust->files[4] = "models/locust/leg_back_left_lower.sgf";
	newLocust->files[5] = "models/locust/leg_back_left_upper.sgf";
	newLocust->files[6] = "models/locust/leg_back_right_lower.sgf";
	newLocust->files[7] = "models/locust/leg_back_right_upper.sgf";
	newLocust->files[8] = "models/locust/leg_front_left.sgf";
	newLocust->files[9] = "models/locust/leg_front_right.sgf";
	newLocust->files[10] = "models/locust/leg_middle_left.sgf";
	newLocust->files[11] = "models/locust/leg_middle_right.sgf";
	newLocust->files[12] = "models/locust/mouth.sgf";
	
	newLocust->state=LS_Stop;
	
	newLocust->model= malloc(sizeof(Model));
	LoadModel(newLocust->model, newLocust->files, 13);
	
	newLocust->main =initNode();
	newLocust->main->modelPart = NULL;
	setNodeTranslation(newLocust->main, 0.0, 0.0, 0);
	setNodeRotation(newLocust->main, 90.0, 0.0, -1.0, 0.0);
	setNodeTranslation(newLocust->main, 0.0, 0.3, 0.0);
	setNodeScale(newLocust->main, 0.8, 0.8, 0.8);
	
	newLocust->body =initNode();
	newLocust->body->modelPart= newLocust->model->modelParts[1];
	addChild(newLocust->main, newLocust->body);
	
	newLocust->antennae= initNode();
	newLocust->antennae->modelPart= newLocust->model->modelParts[0];
	setNodeTranslation(newLocust->antennae, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->antennae);
	
	newLocust->eyes= initNode();
	newLocust->eyes->modelPart= newLocust->model->modelParts[2];
	setNodeTranslation(newLocust->eyes, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->eyes);
	
	newLocust->head= initNode();
	newLocust->head->modelPart= newLocust->model->modelParts[3];
	setNodeTranslation(newLocust->head, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->head);
	
	
	newLocust->backLeftLowerLeg= initNode();
	newLocust->backLeftLowerLeg->modelPart= newLocust->model->modelParts[4];
	setNodeTranslation(newLocust->backLeftLowerLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->backLeftLowerLeg);
	
	newLocust->backLeftUpperLeg= initNode();
	newLocust->backLeftUpperLeg->modelPart= newLocust->model->modelParts[5];
	setNodeTranslation(newLocust->backLeftUpperLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->backLeftUpperLeg);
	
	newLocust->backRightLowerLeg= initNode();
	newLocust->backRightLowerLeg->modelPart= newLocust->model->modelParts[6];
	setNodeTranslation(newLocust->backRightLowerLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->backRightLowerLeg);
	
	newLocust->backRightUpperLeg= initNode();
	newLocust->backRightUpperLeg->modelPart= newLocust->model->modelParts[7];
	setNodeTranslation(newLocust->backRightUpperLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->backRightUpperLeg);
	
	newLocust->frontLeftLeg= initNode();
	newLocust->frontLeftLeg->modelPart= newLocust->model->modelParts[8];
	setNodeTranslation(newLocust->frontLeftLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->frontLeftLeg);
	
	newLocust->frontRightleg= initNode();
	newLocust->frontRightleg->modelPart= newLocust->model->modelParts[9];
	setNodeTranslation(newLocust->frontRightleg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->frontRightleg);
	
	newLocust->middleLeftLeg= initNode();
	newLocust->middleLeftLeg->modelPart= newLocust->model->modelParts[10];
	setNodeTranslation(newLocust->middleLeftLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->middleLeftLeg);	
	
	newLocust->middleRightLeg= initNode();
	newLocust->middleRightLeg->modelPart= newLocust->model->modelParts[11];
	setNodeTranslation(newLocust->middleRightLeg, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->middleRightLeg);	

	newLocust->mouth= initNode();
	newLocust->mouth->modelPart= newLocust->model->modelParts[12];
	setNodeTranslation(newLocust->mouth, 0.0, 0.0, 0);
	addChild(newLocust->body, newLocust->mouth);	
	
	return newLocust;
	
}

void releaseLocust(Locust *_locust){}
void setLocustSize(Locust *Locust, GLfloat _locustSize){}
